<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />

    <style type="text/css">
        .class-title {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
            font-size: 20px;
            font-weight: bold;
            color: #00BFFF;
        }

        .class-hr {
            margin-top: 5px;
            height: 1px;
            border: none;
            border-top: 1px solid #DCDCDC;
        }

        .class-seqno {
            margin-top: 3px;
            margin-left: 10px;
            margin-right: 25px;
            font-size: 10px;
            color: #808080;
            font-weight: bold;
            text-align: right;
        }

        .class-table {
            width: 100%;
            text-align: left;
            color: black;
            font-size: 13px;
            margin-left: 2%;
            width: 100%;
            table-layout: fixed;
        }

        .class-td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            质检员检测单
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">工序</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择工序" id="opCode" value="" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectOpCode()"></i>
                </div>
            </li>
        </ul>
        <p></p>
        <p></p>
        <div class="aui-btn aui-btn-info aui-btn-block" style="margin-top:20px;" onclick='createChkBill()'>
            查询检测单</div>

        <div id="divhtml" style="display: block;width:100%;overflow-y: scroll;margin-top:10px;"></div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var chkTypeCode = "";     //检测单类型
    var chkTypeCodeSjjc = ""; //检测单类型(首件检测)
    var chkBillCode = "";  //检测单号

    //初始化查询仓库下拉框
    apiready = function () {
        var query = api.pageParam.query;
        chkTypeCode = query.chkTypeCode;
        chkTypeCodeSjjc = query.chkTypeCodeSjjc;
    }

    //回车事件
    $("#opCode").on('keypress', function (e) {
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            $("#opCode").blur();
            createChkBill();
        }
    });

    //选择工序
    function goSelectOpCode() {
        api.openWin({
            name: 'paOpCodeDaq',
            url: 'paOpCodeDaq.html',
            pageParam: {
                code: "",
                name: "qcmChkBillCreateZJY",
            }
        });
    }

    //选择工序回调函数
    function setOpCode(id, code, name) {
        $("#opCode").val(code);
        //创建质检员检测单：当前工序第一个件
        createChkBill();
    }

    //创建检测单
    function createChkBill() {
        var opCode = $("#opCode").val();
        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "工序不能为空!",
                duration: 3000
            });
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/chkBillCreateSaveZjy";
        var data = {
            values: {
                chkTypeCode: chkTypeCode, //检测单类型
                chkTypeCodeSjjc: chkTypeCodeSjjc, //检测单类型(首件)
                opCode: opCode, //工序
                un: un
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {

                    chkBillCode = myobj.chkBillCode
                    doSearchChkBillDetails();

                } else {
                    chkBillCode = "";
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //查询质检员检测单
    function doSearchChkBillDetails() {

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getChkBillDetailsZjy";
        var data = {
            values: {
                chkBillCode: chkBillCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {
                    list = eval(myobj.list);
                    if (list != null && list.length > 0) {
                        createTable();
                    } else {
                        $api.html($api.byId("divhtml"), "");
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $api.html($api.byId("divhtml"), "");
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //构造表格数据
    function createTable() {
        var html = "";
        //遍历
        for (var i = 0; i < list.length; i++) {
            // 序号
            html += "<div class='class-seqno'>";
            html += "<span>" + (i + 1) + "</span>";
            html += "</div>";
            //表格
            html += "<div style='margin-left:10px;margin-right:15px;'>";
            html += "<table class='class-table'>";
            html += "<tr>";
            html += "<td class='class-td'>检测单号:    " + list[i].chkBillCode + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td'>物料编码:    " + list[i].mrlCode + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td'>物料名称:    " + list[i].mrlName + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td'>序  列  号:    " + list[i].serialNo + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td'>工序编码:    " + list[i].opCode + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td'>工序名称:    " + list[i].opName + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td'>工  单  号:    " + list[i].workOrderCode + "</td>";
            html += "</tr>";
            html += "<tr>";
            if (list[i].chkResult == "0" || list[i].chkResult == "1") {
                html += "<td class='class-td' style='color:red;'>处理结果:    " + list[i].chkResultName + "</td>";
            } else {
                html += "<td class='class-td' style='color:green;'>处理结果:    " + list[i].chkResultName + "</td>";
            }
            html += "</tr>";
            if (list[i].chkResult == "0") {
                html += "<tr>";
                html += "<td class='class-td'>";
                html += "<div class='aui-btn aui-btn-info' onclick='deal(\"" + list[i].chkBillDetailsId + "\",\"" + list[i].chkBillCode + "\")'>";
                html += "处理</div></td>";
                html += "</tr>";
            }
            html += "</table>";
            html += "<hr class='class-hr' />";
            html += "</div>";
        }

        $api.html($api.byId("divhtml"), html);
    }

    //处理
    function deal(chkBillDetailsId, chkBillCode) {
        api.openWin({
            name: 'qcmChkBillDealSJJC',
            url: 'qcmChkBillDealSJJC.html',
            pageParam: {
                chkBillDetailsId: chkBillDetailsId,
                chkBillCode: chkBillCode,
                name: "qcmChkBillCreateZJY",
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>